package test5.lupeng.jf.com.teamdemo.adapter;


import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import test5.lupeng.jf.com.teamdemo.R;
import test5.lupeng.jf.com.teamdemo.activitys.TitleCheckActivity;
import test5.lupeng.jf.com.teamdemo.bean.response.ResponseTitleCheck;
import test5.lupeng.jf.com.teamdemo.untils.GlideCircleTransform;

//文章评论列表的适配器
public class TitleCheckAdapter extends RecyclerView.Adapter{

    ArrayList<ResponseTitleCheck.ResultBean> results;

    public TitleCheckAdapter( ArrayList<ResponseTitleCheck.ResultBean> results){
        this.results = results;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_titlecheck, parent,false);
        TitleCheckViewHolder holder = new TitleCheckViewHolder(view);
        return holder;
    }

    public class TitleCheckViewHolder extends RecyclerView.ViewHolder{

        private final ImageView iv_head_image;
        private final TextView tv_user_name;
        private final TextView checkMessage;

        public TitleCheckViewHolder(View itemView) {
            super(itemView);
            iv_head_image = itemView.findViewById(R.id.iv_head_image);
            tv_user_name = itemView.findViewById(R.id.tv_user_name);
            checkMessage = itemView.findViewById(R.id.checkMessage);
        }
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        TitleCheckViewHolder holder1 = (TitleCheckViewHolder) holder;
        ResponseTitleCheck.ResultBean bean = results.get(position);
        Glide.with(holder1.itemView.getContext())
                .load(bean.getAuthor().getHeadProtrait())
                .transform(new GlideCircleTransform(holder1.itemView.getContext()))
                .into(holder1.iv_head_image);

        holder1.tv_user_name.setText(bean.getAuthor().getUsername());
        holder1.checkMessage.setText(bean.getContent());

    }

    @Override
    public int getItemCount() {
        return results.size();
    }
}
